﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using 纺织贸易管理系统;

namespace BLL
{
   public static  class AccessBLL
    {
        public static string userid { get; set; }
        /// <summary>
        /// 检查是否有权限
        /// </summary>
        /// <param name="formname"></param>
        /// <returns>有权限返回True,否则返回False</returns>
        public static bool CheckAccess(string formname)
        {
            var acc = AccessTableService.GetOneAccessTable(x => x.AccessName == formname&&x.UserID ==userid);
            if(acc.AccessName ==string.Empty )
            {
                //管理员默认有权限否则没有权限
                var users=Connect.dbcontext.Queryable<Yhb>().Select(x=>x.YHBH).Distinct().ToList();
                var accesslist=new List<AccessTable>();
                foreach (var item in users)
                {
                    accesslist.Add( new AccessTable() { Access = true, AccessName = formname, UserID =item } );
                }
                AccessTableService.InsertAccessTablelst(accesslist);
                return true;
            }
            else
            {
                if(!acc.Access )
                {
                    if(acc.AccessName!= "超期库存价格可见")
                    {
                        if (acc.AccessName != "销售价格填写")
                        {
                            Tools.ShowMessageBox.ShowErrorBox("对不起！您没有权限使用该功能！请与管理员联系开通该功能");
                        }
                    }
                    
                }               
                return acc.Access;
            }
        }
    }
}
